package cn.tedu;

import java.awt.*;
import java.util.Random;

public class Ball {
    int x;
    int y;
    int width=100;
    int height=100;
    Color color;
    Random random=new Random();
    int speed=3;

    int alive=1;

    int flag=random.nextInt(4);

    public Ball(){


        this.x=random.nextInt(1920);
        this.y=random.nextInt(1080);

        this.color=new Color(random.nextInt(255),random.nextInt(255),random.nextInt(255));
    }

    public void move(){
        if(flag==0){
            y-=speed;
            x-=speed;
        }else if(flag==1){
            y-=speed;
            x+=speed;
        }else if(flag==2){
            y+=speed;
            x+=speed;
        }else if(flag==3){
            y+=speed;
            x-=speed;
        }

        if(y<0){
            if(this.flag==0){
                this.flag=3;
            }else if(this.flag==1){
                this.flag=2;
            }
        }

        if(x<0){
            if(this.flag==0){
                this.flag=1;
            }else if(this.flag==3){
                this.flag=2;
            }
        }

        if(x>1920){
            if(this.flag==1){
                this.flag=0;
            }else if(this.flag==2){
                this.flag=3;
            }
        }

        if(y>1080){
            if(this.flag==2){
                this.flag=1;
            }else if(this.flag==3){
                this.flag=0;
            }
        }
    }
}
